import { ElNotification, ElMessage, ElMessageBox } from 'element-plus'
import nProgress from 'nprogress'

// 公共方法
import {useRouter} from 'vue-router'
const router = useRouter()


// 通知提示框
export function toast(message, type = "success", offset = 0, duration = 3000, dangerouslyUseHTMLString = false) {
    ElNotification({ message, type, duration, dangerouslyUseHTMLString, offset })
}

// 消息确认框
export function showModal(content = "提示内容", type = "warning", title = "") {
    return ElMessageBox.confirm(
        content, title, { confirmButtonText: '确定', cancelButtonText: '取消', type, }
    )
}
// 消息提示框
export function showMessage(message = "提示内容", type = "warning") {
    return ElMessage({ message, type, })
}
// 显示全屏loading
export function showFullLoading() {
    nProgress.start()
}
// 隐藏全屏loading// 显示全屏loading
export function hideFullLoading() {
    nProgress.done()
}
// 弹出输入框
export function showPrompt(tip, value_max = 200) {
    return ElMessageBox.prompt(tip, '', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        // inputValue: value
        inputValidator: (value) => {
            if (value === null || value.length < 1 || value.length > value_max) {
                return false;
            }
        },
        inputErrorMessage: '此项不能为空，最多可输入' + value_max + '个字符',

    })
}

// 查询、过滤、搜索
export function queryFilters(query) {
    let q = []
    for (const key in query) {
        if (query[key]) {
            q.push(`${key}=${encodeURIComponent(query[key])}`)
        }
    }
    let r = q.join("&")
    r = r ? ("?" + r) : ""
    return r
}

// 格式化日期
export function formatDateFun() {
    const formatDate = (row, column) => {
        // 获取单元格数据
        let data = row[column.property];
        if (data == null) {
            return null;
        }
        let dt = new Date(data);
        return (
            dt.getFullYear() + "年" + (dt.getMonth() + 1) + "月" + dt.getDate() + "日"
        );
    };
    return formatDate
}


// 内容类型
export function getContentType(str = '') {
    const contentType = [
        // {
        //     label: "文章",
        //     value: "1",
        // },
        {
            label: "视频",
            value: "2",
        },
        // {
        //     label: "图片",
        //     value: "3",
        // },

    ]
    // console.log(str,'strstrstrstrstrstr')
    // if (str != '') {
    //     let contentTypeTemp = []
    //     if (str.indexOf(",") != -1) {
    //         let strArr = str.split(",")
    //         strArr.forEach(item => {
    //             contentTypeTemp.push(contentType.find(item2 => item2.value == item))
    //         })

    //     } else {
    //         strArr.forEach(item => {
    //             contentTypeTemp.push(contentType.find(item2 => item2.value == str))
    //         })
    //     }
    //     return contentTypeTemp
    // }

    return contentType
}

export function goTo(path){
    router.push({ path: path })
}

